<%@page contentType="text/html; charset=UTF-8" %>
<script>
	jQuery(function ($) {
		$("#saveBtn").click(function () {
			// 编号重复
			if ($("#codeErr").text()) {
				return;
			}
			//$("#saveForm").submit();
			$("#saveForm").ajaxSubmit(function (data) {
				$("#mainDiv").html(data);
			});
		});

		$("#create-code").blur(function () {
			$("#codeErr").text("");
			if (this.value) {
				$.ajax({
					url: '/type/exists?code=' + this.value,
					success(exists) {
						$("#codeErr").text(exists ? "编号已存在！" : "");
					}
				});
			}
		});
	});
</script>

<div class="page-header">
	<h3>新增字典类型</h3>
</div>
<div style="width: 60%;">
	<form id="saveForm" method="post" action="/type/save" class="form-horizontal" role="form">
		<div class="form-group">
			<label for="create-code" class="col-sm-2 control-label">
				编码<span style="color:red;">*</span>
			</label>
			<div class="col-sm-10">
				<input name="code" type="text" class="form-control" id="create-code" placeholder="编码作为主键，不能是中文">
				<div id="codeErr" style="color: red;"></div>
			</div>
		</div>

		<div class="form-group">
			<label for="create-name" class="col-sm-2 control-label">名称&nbsp;</label>
			<div class="col-sm-10">
				<input name="name" type="text" class="form-control" id="create-name">
			</div>
		</div>

		<div class="form-group">
			<label for="create-describe" class="col-sm-2 control-label">描述&nbsp;</label>
			<div class="col-sm-10">
				<textarea name="description" class="form-control" rows="3" id="create-describe"></textarea>
			</div>
		</div>
	</form>
	<div style="text-align: center">
		<button id="saveBtn" class="btn btn-primary" style="margin-right: 20px">保存</button>
		<%--<button class="btn btn-default" url="/type/index.html">取消</button>--%>
		<button class="btn btn-default" onclick="back()">取消</button>
	</div>
</div>